package com.shz.appletsapi.config.security.social.github.connect;

import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import org.springframework.social.oauth2.OAuth2Operations;
import org.springframework.social.oauth2.OAuth2Template;

import com.shz.appletsapi.config.security.social.github.api.GitHub;
import com.shz.appletsapi.config.security.social.github.api.impl.GitHubTemplate;

public class GitHubServiceProvider extends AbstractOAuth2ServiceProvider<GitHub> {
	
	
	private static final String GET_AUTHORIZE="https://github.com/login/oauth/authorize";
	private static final String GET_ACCESSTOKEN="https://github.com/login/oauth/access_token";
	

	public GitHubServiceProvider(String appId,String appSecret) {
		super(getOAuth2Template(appId,appSecret));
		// TODO Auto-generated constructor stub
	}
	
	private static OAuth2Operations getOAuth2Template(String appId,String appSecret) {
		OAuth2Template oAuth2Template =new OAuth2Template(appId, appSecret, GET_AUTHORIZE, GET_ACCESSTOKEN);
		oAuth2Template.setUseParametersForClientAuthentication(true);
		return oAuth2Template;
		
	}

	@Override
	public GitHub getApi(String accessToken) {
		// TODO Auto-generated method stub
		return new GitHubTemplate(accessToken);
	}

}
